#ifndef __VECTOR_H__
#define __VECTOR_H__
#include <cstdlib>
#include <stdlib.h>
#include "allocator.h"

/** 
* Simple vector implementation.
*/

template<typename T, int CAPACITY=400>
class Vector{
private:
	int capacity_;
	int size_;
	T* table_;

	void reallocate(){
		T* old = table_;
		capacity_ += capacity_;
		table_ = (T*)malloc(sizeof(T)*capacity_);
		for(int i = 0; i < capacity_/2; ++i){
			table_[i]=old[i];
		}
		free(old);
	}

public:
	Vector() : capacity_(CAPACITY), size_(0) {
		//table_ = new T[capacity_];
		table_ = (T*)malloc(sizeof(T)*capacity_);
	}
	void push_back(T t){
		if(size_+1 > capacity_)
			reallocate();
		table_[size_++] = t;
	}

	T remove(int i){
		T t = table_[i];
		--size_;
		for(int j = i; j < size_; ++j){
			table_[j]=table_[j+1];
		}
		return t;
	}
	int size() const{
		return size_;
	}

	T& operator[](int i){
		return table_[i];
	}
	const T& operator[](int i) const{
		return table_[i];
	}
};

#endif
